package com.lkd.controller;

import com.lkd.dto.NodeQueryDTO;
import com.lkd.entity.Node;
import com.lkd.report.NodeCount;
import com.lkd.result.R;
import com.lkd.result.TableInfo;
import com.lkd.service.NodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Z.lx
 * @Date: 2025/8/17 14:07
 * @Description:
 **/
@RestController
@RequestMapping("/api/vm-service/node")
@Slf4j
public class NodeController {
    @Autowired
    private NodeService nodeService;

    /**
     * @Description 查询
     * @Param [nodeDTO]
     * @Date 2025/8/17 15:42
     **/
    @GetMapping("/search")
    public TableInfo<Node> list(NodeQueryDTO NodeQueryDto) {
        log.info("查询点位信息:{}", NodeQueryDto);
        return nodeService.selectNodeList(NodeQueryDto);
    }

    /**
     * @Description 新增
     * @Param [nodeDTO]
     * @Date 2025/8/17 15:42
     **/
    @PostMapping
    public boolean add(@RequestBody Node node) {
        return nodeService.add(node);
    }

    /**
     * @Description 修改
     * @Param [nodeDTO]
     * @Date 2025/8/17 15:42
     **/
    @PutMapping("/{nodeId}")
    public boolean update(@RequestBody Node node) {
        log.info("修改点位信息:{}", node);
        return nodeService.update(node);
    }
    /**
     * @Description 删除
     * @Param [nodeId]
     * @Date 2025/8/17 15:42
     **/
    @DeleteMapping("/{nodeId}")
    public boolean delete(@PathVariable String nodeId) {
        log.info("删除点位:{}", nodeId);
        return nodeService.delete(nodeId);
    }
    /**
     * @Description 获取点位信息
     * @Param [nodeId]
     * @Date 2025/8/17 15:42
     **/
    @GetMapping("/vmList/{nodeId}")
    public Node get(@PathVariable String nodeId) {
        log.info("获取点位:{}", nodeId);
        return nodeService.getByNodeId(nodeId);
    }

    @GetMapping("/count")
    public Integer countNode() {
        return nodeService.nodeCount();
    }
    @GetMapping("/nodeCollect")
    public R<List<NodeCount>> countNodeCollect() {
        return R.ok(nodeService.nodeCollect());
    }
}
